﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebAp0001.Domain.Entity;

namespace WebAp0001.Domain
{
    public class DbInitializeHelper
    {
        public static void Initializer()
        {
            using (var db=new Admin4000DbContext())
            {
               var dbExist= db.Database.EnsureCreated();
                if(!dbExist)
                {
                    var bran = new Brand
                    {
                        BrandName = "华为",
                        Description = "中国的",
                    };
                    db.Brands.Add(bran);

                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName ="华为001",
                        ShortDesc="中国是一个简单的介绍",
                        FullDesc="这个是一个详细的介绍",
                        BrandId=bran.Id
                    },new Product
                    {
                        ProductName ="华为002",
                        ShortDesc="这个是一个简单的介绍",
                        FullDesc="这个是一个详细的介绍",
                        BrandId=bran.Id
                    }

                    });
                    db.SaveChanges();

                }


            }


        }

    }
}
